package main.java.servlet;

import main.java.dao.UserDao;
import main.java.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "loginServlet",urlPatterns = "/login")
public class LoginServlet extends HttpServlet {

    private UserDao userDao = new UserDao();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("doGet");

//        resp.getWriter().write("login");
//        resp.sendRedirect("/web/login.jsp");
//        System.out.println(req.getContextPath());
//        System.out.println(req.getServletPath());
//        req.getRequestDispatcher(req.getContextPath()+"/web/index.jsp").forward(req,resp);
        List<User> userList = userDao.getAll();
        req.setAttribute("userList",userList);
        req.getRequestDispatcher("/WEB-INF/page/user.jsp").forward(req,resp);
//        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.printf("doPost");
        super.doPost(req, resp);
    }
}
